<template>
  <transition name="fade" @after-leave="destroy">
    <div v-show="isVisible" class="dialog-mask" :class="{ 'font-size-14': isMobile() }">
      <img v-if="icon" class="msg-img" :src="icon" alt="" />
      {{ message }}
    </div>
  </transition>
</template>

<script setup lang="ts">
import { isMobile } from '@kukefe/kkutils'
const props = defineProps<{
  message: string
  icon: string
  duration: number
  destroy: (el: Element) => void
}>()

// 控制显示处理
const isVisible = ref(false)

onMounted(() => {
  isVisible.value = true

  const timer = setTimeout(() => {
    isVisible.value = false
    clearTimeout(timer)
  }, props.duration)
})
</script>
<style lang="scss">
.dialog-mask {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  padding: 9px 12px;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.7);
  z-index: 10000002;
  font-size: 16px;
  font-weight: 400;
  // white-space: nowrap;
  color: #ffffff;
}

/** 
  *2倍处理
*/
.font-size-14 {
  font-size: 28px;
  line-height: 28px;
  max-width: 80%;
}

.fade-enter-active,
.fade-leave-active {
  transition: all 0.5s;
}

.fade-enter-from,
.fade-leave-to {
  opacity: 1;
  transform: translate3d(-50%, -100%);
}

.msg-img {
  display: inline-block;
  width: 20px;
  height: 20px;
  margin-bottom: 3px;
}
</style>
